// pages/user/user.js
Page({
    /**
     * 页面的初始数据
     */
    data: {
        logintext: '点击头像登录',
        isShow: false,
        userInfo: {},
        defaultImg: "https://img0.baidu.com/it/u=1572439348,1806926901&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=500",
        num: 5,
        isDown: 0,
        image: "../../image/user-down.png",
        newImg: "../../image/user-new.png",
        gift_first: "../../image/user-gift1.png",
        gift_second: "../../image/user-gift2.png",
        menuData: [{
                id: "1",
                imgUrl: "../../image/user-wd.png",
                text: "我的订单",
                pageUrl: "../../pages/goods/goods"
            },
            {
                id: "2",
                imgUrl: "../../image/user-kf.png",
                text: "咖啡钱包",
                pageUrl: "../../components/userHome/moneybag/moneybag"
            },
            {
                id: "3",
                imgUrl: "../../image/user-yh.png",
                text: "优惠券",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
            {
                id: "4",
                imgUrl: "../../image/user-lp.png",
                text: "礼品卡",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
            {
                id: "5",
                imgUrl: "../../image/user-zh.png",
                text: "账户余额",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
            {
                id: "6",
                imgUrl: "../../image/user-fp.png",
                text: "发票管理",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
            {
                id: "7",
                imgUrl: "../../image/user-dh.png",
                text: "兑换优惠",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
            {
                id: "8",
                imgUrl: "../../image/user-bz.png",
                text: "帮助反馈",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
            {
                id: "9",
                imgUrl: "../../image/user-zs.png",
                text: "招商加盟",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
            {
                id: "10",
                imgUrl: "../../image/user-kw.png",
                text: "口味定制",
                pageUrl: "../../components/userHome/userpurse/userpurse"
            },
        ]

    },
    share(){
        wx.navigateTo({
          url: '../../components/userHome/share/share',
        })

    },
    switchTab(e) {
        console.log("Pageurl", e.currentTarget.dataset.pageid)
        console.log("pageId", e.currentTarget.dataset.id)
        // var index = parseInt("1",e.currentTarget.dataset.index)
        // if (e.currentTarget.dataset.id = 1) {
        //     wx.switchTab({
        //         url: '../../pages/goods/goods',
        //     })
        // } 
    },
    navigato(e){
            wx.navigateTo({
                url:""+e.currentTarget.dataset.pageid
            })
    },
    onLoad() {
        // 获取上次登录的信息
        let isShow = wx.getStorageSync('isShow') || false
        let userInfo = wx.getStorageSync('userInfo')
        if (isShow) {
            // 已经授权过
            this.setData({
                isShow: true,
                userInfo: userInfo
            })
        }
        this.switchTab()
    },
    // 方便在小程序中展示你的微信头像、昵称
    getUserInfo() {
        let that = this
        wx.getUserProfile({
            desc: '获取用户信息',
            //   成功
            success: (res) => {
                console.log(res.userInfo);
                let userInfo = res.userInfo
                that.setData({
                    isShow: true,
                    userInfo: userInfo
                })
                // 把用户信息存起来，不用每次登录
                wx.setStorageSync('isShow', true)
                wx.setStorageSync('userInfo', userInfo)
            },
            //   失败
            fail() {
                wx.showToast({
                    title: '登录失败!!!',
                    icon: "none"
                })

            }
        })
    },

    Down() {
        if (this.data.isDown == 0) {
            this.setData({
                isDown: 1,
                image: "../../image/user-up.png"
            })
        } else {
            this.setData({
                isDown: 0,
                image: "../../image/user-down.png"
            })
        }
    },

    /**
     * 生命周期函数--监听页面加载
     */

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    }
})